package training.collection;

import java.util.ArrayList;
import java.util.List;

public class PhoneBook {
	private static List<Person> database = new ArrayList<Person>();
	
	private static void init(){
		Person pData = new Person();
		pData.setName("Mpu Tantular");
		pData.setPhone("888-888");

		Person pData1 = new Person();
		pData1.setName("Ken Arok");
		pData1.setPhone("888-888");
		
		Person pData2 = new Person();
		pData2.setName("Gajah Mada");
		pData2.setPhone("888-888");
		
		database.add(pData);
		database.add(pData1);
		database.add(pData2);
	}
	
	private static List<Person> search(String nama){
		List<Person> hasil = new ArrayList<Person>();
		for (Person person : database) {
			if(person.getName().contains(nama)){
				hasil.add(person);
			}
		}
		return hasil;
	}
	
	public static void main(String[] args) {
		init();
		for (Person p : search("Ar")) {
			System.out.println(p.toString());
		}
		
	}
}
